<?php

/**
 * system actions.
 *
 * @package    rpgcom
 * @subpackage system
 * @author     Your name here
 */
class systemActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Systems = SystemPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->System = SystemPeer::retrieveByPk($request->getParameter('idsystem'));
    $this->forward404Unless($this->System);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new SystemForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new SystemForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($System = SystemPeer::retrieveByPk($request->getParameter('idsystem')), sprintf('Object System does not exist (%s).', $request->getParameter('idsystem')));
    $this->form = new SystemForm($System);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($System = SystemPeer::retrieveByPk($request->getParameter('idsystem')), sprintf('Object System does not exist (%s).', $request->getParameter('idsystem')));
    $this->form = new SystemForm($System);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($System = SystemPeer::retrieveByPk($request->getParameter('idsystem')), sprintf('Object System does not exist (%s).', $request->getParameter('idsystem')));
    $System->delete();

    $this->redirect('system/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $System = $form->save();

      $this->redirect('system/edit?idsystem='.$System->getIdsystem());
    }
  }
}
